package com.cuckoo.mall.thus.goodmultipledetail;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.bgn.baseframe.utils.BaseStringUtil;
import com.bgn.baseframe.utils.UiUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.ProductAttribute;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * Created by wanglun on 2018/3/3.
 */

public class GoodPickAdapter extends BaseQuickAdapter<ProductAttribute, BaseViewHolder> {


    public GoodPickAdapter(@Nullable List<ProductAttribute> data) {
        super(R.layout.list_item_good_pick, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, final ProductAttribute item) {
        if (item.getValue() != null) {
            helper.setText(R.id.tv_property_name, BaseStringUtil.firstCharUpperCase(item.getName()));
            final TagFlowLayout flowLayout = helper.getView(R.id.flow_propertys);
            flowLayout.setAdapter(new TagAdapter(item.getValue()) {

                @Override
                public void onSelected(int position, View view) {
                    super.onSelected(position, view);
                    if (item.getValue().size() > 0) {
                        item.setSelectedValue(item.getValue().get(position));
                    }
                }

                @Override
                public void unSelected(int position, View view) {
                    super.unSelected(position, view);
                    item.setSelectedValue("");
                }

                @Override
                public View getView(FlowLayout parent, int position, Object o) {
                    TextView tv = (TextView) UiUtil.inflate(R.layout.list_item_flow_property);
                    tv.setText(o.toString());
                    return tv;
                }
            });
            flowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
                @Override
                public boolean onTagClick(View view, int position, FlowLayout parent) {
                    return false;
                }


            });
        }

    }

//    public interface PropertySelectedCallback{
//        void onSelected(int propertyPosition,int selectedItemPosition,Stiring selectedId)
//    }
//

}
